import cv2


cv2.namedWindow('video', cv2.WINDOW_NORMAL)
cv2.resizeWindow('video', 680, 480)
# 打开摄像头
img = cv2.VideoCapture(0)
if not img.isOpened():
    print("error")
    exit()
while True:
    # 逐帧捕获
    ret, frame = img.read()
    # 如果读取到帧
    if ret:
        # 灰色图像COLOR_BGR2GRAY
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow('video', gray)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

print("宽：",img.get(cv2.CAP_PROP_FRAME_WIDTH))
print("高：",img.get(cv2.CAP_PROP_FRAME_HEIGHT))
print("帧率：",img.get(cv2.CAP_PROP_FPS))


img.release()
cv2.destroyAllWindows()